Skip to content

fix(exporter-otlp-proto-http): log response body on metric export failure#5159

Open
amir-h-rassafi wants to merge 1 commit intoopen-telemetry:mainfrom
amir-h-rassafi:fix/http-metric-exporter-log-response-body
Open

fix(exporter-otlp-proto-http): log response body on metric export failure#5159
amir-h-rassafi wants to merge 1 commit intoopen-telemetry:mainfrom
amir-h-rassafi:fix/http-metric-exporter-log-response-body

Conversation

@amir-h-rassafi
Copy link
Copy Markdown

Description

The HTTP metric exporter logs only the status code and reason phrase on a non-2xx response, e.g. 400, Bad Request. The response body — where the collector explains why it rejected the
request (payload too large, invalid attribute, unsupported content-type, etc.) — is dropped. That makes 4xx errors hard to debug without patching the SDK or proxying traffic to the
collector.

This change captures resp.text (truncated to 1024 chars) and includes it in the non-retryable failure log and the retries-exhausted log.

Scope is metric exporter only. The trace and log HTTP exporters have the same gap; happy to follow up in a separate PR if this lands.

Fixes # (no linked issue — small log-only change, no behavior change beyond more verbose error output)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added test_failure_logs_response_body — asserts the response body text appears in the error log on a 400.
  • Added test_failure_logs_truncates_long_response_body — asserts bodies over 1024 chars are truncated with a ...[truncated] marker.
  • Ran python -m pytest exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/ — all tests pass except one pre-existing failure (test_aggregation_temporality, env leakage) that
    also fails on main without this change.
  • ruff check and ruff format --check clean. No new pylint warnings introduced.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Things to fix yourself before submitting

  1. CHANGELOG #XXXX placeholder — once GitHub assigns a number, update both #XXXX and /pull/XXXX in CHANGELOG.md, amend, force-push.
  2. The "Fixes # (no linked issue)" line — maintainers may ask why you didn't open an issue first (AGENTS.md asks for that). Either open a quick one and link it, or be ready to explain in a
    PR comment that this is a small log-output-only change with no behavior change.
  3. Read the body once and tweak phrasing so it reads as yours, not generic. Specifically: the parenthetical examples list ("payload too large, invalid attribute, …") and the "Scope is
    metric exporter only" sentence are the most generic-sounding bits — easy targets to rewrite.

…er error log

When the OTLP HTTP metric exporter receives a non-2xx response, it currently
logs only the HTTP status code and reason phrase (e.g. "400, Bad Request"),
discarding the response body where the collector reports the actual rejection
reason (payload too large, invalid attribute, unsupported content-type, etc.).
This makes 4xx errors very hard to diagnose without patching the SDK or
proxying traffic.

Include the response body (truncated to 1024 chars) in the non-retryable
failure log and in the retries-exhausted log so the collector's rejection
detail is visible to users.
@amir-h-rassafi amir-h-rassafi requested a review from a team as a code owner April 28, 2026 16:11
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 28, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: amir-h-rassafi / name: Amir Rassafi (f148906)

@DylanRussell
Copy link
Copy Markdown
Contributor

Would #5155 resolve your issue ? Can you add your review to that PR ?

@amir-h-rassafi
Copy link
Copy Markdown
Author

amir-h-rassafi commented Apr 29, 2026

Would #5155 resolve your issue ? Can you add your review to that PR ?

Thank you for having a look, Yes I think so but logic looks like not correct/helpful, left a comment https://github.com/open-telemetry/opentelemetry-python/pull/5155/changes#r3164122609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants